package com.demo.core.service.base.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.core.dao.MemberRoleDao;
import com.demo.core.model.MemberRole;
import com.demo.core.model.Role;
import com.demo.core.service.base.MemberRoleService;
/**
 * 会员角色服务实现类
 * @author ryuu.kk
 *
 */
public class MemberRoleServiceImpl implements MemberRoleService {
	/**
	 * 会员角色访问层
	 */
	private MemberRoleDao memberRoleDao;
	@Override
	public Long save(MemberRole memberRole) {
		return memberRoleDao.insert(memberRole);
	}
	@Override
	public boolean exists(Long id) {
		return memberRoleDao.exists(id);
	}	
	@Override
	public void delete(Long memberRoleId) {
		memberRoleDao.delete(memberRoleId);		
	}
	@Override
	public void deleteAll(Long memberId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("memberId", memberId);
		memberRoleDao.delete(params);
	}
	@Override
	public void updateEnabled(Long memberRoleId, boolean enabled) {
		memberRoleDao.updateEnabled(memberRoleId, enabled);		
	}
	@Override
	public MemberRole find(Long id) {
		return memberRoleDao.select(id);
	}
	@Override
	public List<MemberRole> findMember(Long roleId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("roleId", roleId);
		return memberRoleDao.select(params);
	}
	@Override
	public List<MemberRole> findRole(Long memberId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("memberId", memberId);
		return memberRoleDao.select(params);
	}
	
	@Override
	public List<Role> queryRole(Long memberId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("memberId", memberId);
		return memberRoleDao.queryRole(params);
	}
	@Override
	public List<Role> queryRole(Long siteId, Long userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("siteId", siteId);
		params.put("userId", userId);
		return memberRoleDao.queryRole(params);
	}
	
	public void setMemberRoleDao(MemberRoleDao memberRoleDao) {
		this.memberRoleDao = memberRoleDao;
	}
}
